<?php
/**注意此文档为UTF-8的编码.
 * Created on 2010-6-29
 *
 * @author EXT <isrn@qq.com>
 *
 */
include ('../../includes/global.php');
include ('../global.php');
include ("../power.php");
$dbcfg=Sys::Gp(array('dbcfg','sevenel'));
$donotrender = array('htmleditor','fckeditor','password','hidden');
function grv($type,$blm,$dvalue=false){
	//print_r($type);
	if($dvalue){
		return $dvalue;
		}else{
		switch($type){
				case 'function':{
					$a=explode('#',$blm);
					return $a[0]($a[1]);
					break;
					}
				case '$_GET':{
					return	$_GET[$blm];
					break;
					}
				case '$_SESSION':{
					return	$_SESSION[$blm];
					break;
					}
				case '$_POST':{
					return	$_POST[$blm];
					break;
					}
				case '$_COOKIE':{
					return	$_COOKIE[$blm];
					break;
					}
				case '$_SERVER':{
					return	$_SERVER[$blm];
					break;
					}
				case '$_ENV':{
					return	$_ENV[$blm];
					break;
					}
				case '$_FILES':{
					return	$_FILES[$blm];
					break;
					}
				case '0':{
					return $blm;
					break;
					}
				case '1':{
					break;
					}
				default:{
					return $blm;
					break;
					}
			
				}
			}
	}
 switch($_REQUEST['op']){
	case 'save':{
			
		$id = $_POST['id'];
		$tree_id = $_POST['tid'];
 		$tree=Dgd(array(
						  'db'=>'d_sevenel',
						  'cd'=>"id = $tree_id",
						  'tn'=>"tree",
						  'limit'=>'1'
						));
		$tabname = gettabname($tree['table'],'',true);
		$fld=Dgd(array(
					'db'=>'d_sevenel',
					'cd'=>"tid = $tree_id",
					'tn'=>"fld"
				));
		foreach($fld as $key => $value){
			if($value['fname']==$_POST['zd']){
				$temp=$value;
				}
		}
			$value=$temp;
			switch($value['type']){
				case 'datefield':{
					if($value['zy']!=1){
						if(strtotime($_POST[$value['fname']])){
							$save[$value['fname']] = strtotime($_POST[$value['fname']]);
							}else{
							$save[$value['fname']]=$_POST[$value['fname']];
								}
						}else{
					$save[$value['fname']]=$_POST[$value['fname']];
							}
				break;}
				case 'checkboxgroup':{
					$save[$value['fname']]=implode("#_#",$_POST[$value['fname']]);
				break;}
				case 'password';{
					if($value['yxwk']=='1'){
						if($_POST[$value['fname']]==$_POST[$value['fname'].'-cfrm']){
							$save [$value['fname']] = md5($_POST[$value['fname']]);
						}else{
							ext_request_failure('两次输入不相同');
							exit();
						}
					}else{
						$save [$value['fname']] = md5($_POST[$value['fname']]);
					}
				break;}
			case 'fileup':{
					//print_r($_FILES);exit;
							if($_FILES[$value['fname']]['name']!=''){
							$cp=1;
								//复制文件
							$config=json_decode($value['cfg'],true);
							
							
							$dvalue=array( 0=>array('rar','zip','tar','.tz'),
										   1=>array('jpg','gif','png','bmp'),
										   2=>array('mp3','mp4','avi','wmv','mid','.rm','mvb','mov','wma','wav'),
										   3=>array('doc','xls','txt','ocx','lsx','ppt','pdf','chm'),
										   4=>array('doc','xls','txt','ocx','lsx','ppt','pdf','chm','mp3','mp4','avi','wmv','mid','.rm','mvb','mov','wma','wav','jpg','gif','png','bmp','rar','zip','tar','.tz')		   
												   );
								if(!$_FILES[$value['fname']]['name']){
									$cp=0;
								}
							$otype=substr(strtolower($_FILES[$value['fname']]['name']),-3);
							if(!in_array($otype,$dvalue[$config['type']])){
									$cp=0;
											header("Content-type: text/html; charset: UTF-8");
											echo "{success:true,msg:'%u4E0A%u4F20%u683C%u5F0F%u4E0D%u5141%u8BB8%21%u8BF7%u8054%u7CFB%u7BA1%u5458%21<BR> Upload format is not allowed! Please contact the administrator!'}";
											exit;
							}
							if($_FILES[$value['fname']]['size']/1000>$config['size']){
							$cp=0;
											header("Content-type: text/html; charset: UTF-8");
							echo "{success:true,msg:'%u6587%u4EF6%u5927%u5C0F%u8D85%u8FC7%u9650%u5236%21<br> The file size limit expired!'}";
							exit;
								}
						if($cp){
						$bsname=time();
						$bcname=$bsname.".".$otype;
						$filename="../../uplods/pic/".$bcname;
						$copymes=copy($_FILES[$value['fname']]['tmp_name'],$filename);
						$save[$value['fname']]=$bcname;
						}
						if(in_array($otype,$dvalue[1])){
							if($config['sl1']==1){
						@createthumb($_FILES[$value['fname']]['tmp_name'],".".$otype,$bsname,$config['sl1x'],$config['sl1y'],'1');
								}
								if($config['sl2']==1){
						@createthumb($_FILES[$value['fname']]['tmp_name'],".".$otype,$bsname,$config['sl2x'],$config['sl2y'],'2');
								}
								if($config['sypic']==1){
							$sypicname="../../uplods/sypic/".$bcname;
							$sypicwz="../../uplods/".$config['sytp']."";
							//echo $sypicwz ,$config['sytp'],$config['sywz'];
							@imageWaterMark($filename,$sypicname,$config['sypicwz'],$sypicwz,"",20,'wqy-microhei-lite.ttc',"#00FF00");
								}
								if($config['sytxt']==1){
							$sypicname="../../uplods/sytxt/".$bcname;
							$sypicwz="";
							@imageWaterMark($filename,$sypicname,$config['sytxtwz'],"",$config['sywz'],$config['sywzdx'],$config['syzt'],"#".$config['syys']);
								}
								if($config['sytxt']==1&&$config['sypic']==1){
							$filename="../../uplods/sypic/".$bcname;
							$sypicname="../../uplods/sytp/".$bcname;
							$sypicwz="";
							@imageWaterMark($filename,$sypicname,$config['sytxtwz'],"",$config['sywz'],$config['sywzdx'],$config['syzt'],"#".$config['syys']);
								}
								
								}
					}
				break;}
				default:{
				$save[$value['fname']]=$_POST[$value['fname']];
				}
			}
			$save['tid'] = $tree_id;
			!$_POST['lg']&&$save['lg']='zh';
			$_POST['bdid']&&$save['bdid']=$_POST['bdid'];
			$_POST['bdtid']&&$save['bdtid']=$_POST['bdtid'];
			!$_POST['gid']&&$save['gid']=Mct();
			$save['at']=time();
		//唯一性
		if($id!=0){
		if(Du('sevenel',$tabname,$save,'id',$id,1))
			ext_request('ok');
		}else{
			if(Di('sevenel',$tabname,$save));
			ext_request('ok');
		}
	break;}
	case 'qkzd':{
		$save[$_POST['zd']]='';
		if(Du('sevenel',$_POST['tname'],$save,'id',$_POST['id'],1))
			ext_request('ok');	break;
			}
	case 'gxzd':{
		$save[$_POST['zd']]=$_POST['xz'];
		if(Du('sevenel',$_POST['tname'],$save,'id',$_POST['id'],1))
			ext_request('ok');	break;
			}
 }
?>